package top.canyue.word_range_service.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import top.canyue.word_range.pojo.po.RelEventCondition;
import top.canyue.word_range.pojo.vo.ConditionVo;

import java.util.List;

@Mapper
public interface RelEventConditionMapper extends BaseMapper<RelEventCondition> {
    @Insert("INSERT INTO rel_event_condition(id, event_id, condition_id) " +
            "VALUES(MD5(UUID()),#{eventId},#{conditionId}) ")
    Integer associatedCondition(String conditionId, String eventId);

    @Select("SELECT *  FROM `condition` " +
            "WHERE `condition`.id IN (" +
            "SELECT rel_event_condition.condition_id " +
            "FROM rel_event_condition JOIN event " +
            "ON rel_event_condition.event_id = event.id " +
            "WHERE rel_event_condition.event_id = #{eventId} " +
            ")")
    List<ConditionVo> getConditionListByEvent(String eventId);
}
